//
//  ASSession.m
//  XSignService
//
//  Created by 吴双 on 2023/1/23.
//

#import "ASSession.h"
#import "ASSession+Private.h"
#import <AltSign/AltSign.h>

@implementation ASAccountSession

- (instancetype)initWithSession:(ALTAppleAPISession *)session account:(ALTAccount *)account {
    self = [super init];
    if (self) {
        _teamSessions = [NSMutableDictionary dictionary];
        _session = session;
        _account = account;
    }
    return self;
}

- (ASTeamSession *)teamSessionForTeam:(ALTTeam *)team {
    if (!team) return nil;
    
    ASTeamSession *teamSession = nil;
    @synchronized (self) {
        teamSession = self.teamSessions[team.identifier];
        if (!teamSession) {
            teamSession = [[ASTeamSession alloc] initWithSession:self.session account:self.account team:team];
            teamSession.privateDelegate = self.privateDelegate;
            self.teamSessions[team.identifier] = teamSession;
        }
    }
    return teamSession;
}

@end

@implementation ASTeamSession

- (instancetype)initWithSession:(ALTAppleAPISession *)session account:(ALTAccount *)account team:(ALTTeam *)team {
    self = [super init];
    if (self) {
        _session = session;
        _account = account;
        _team = team;
    }
    return self;
}

@end
